package kliment.geom {
	import flash.geom.Point;
	
	/**
	* ...
	* @author Kliment
	*/
	public class Quadrangle {
		private var _angle:Number = 0;
		
		private var _center:Point;
		private var _point1:Point;
		private var _point2:Point;
		private var _point3:Point;
		private var _point4:Point;
		
		public function Quadrangle(point1:Point, point2:Point, point3:Point, point4:Point, center:Point = null) {
			_point1 = point1;
			_point2 = point2;
			_point3 = point3;
			_point4 = point4;
			
			_center = (center)?center:point1.clone();
		}
		
		private function _rotate(angle:Number):void {
			_point1 = Geom.rotatePoint(_point1, _center, angle);
			_point2 = Geom.rotatePoint(_point2, _center, angle);
			_point3 = Geom.rotatePoint(_point3, _center, angle);
			_point4 = Geom.rotatePoint(_point4, _center, angle);
		}
		
		public function clone():Quadrangle {
			return new Quadrangle(_point1, _point2, _point3, _point4);
		}
		
		public function get angle():Number { return _angle; }
		public function set angle(value:Number):void { 
			_angle = Geom.getNormalAngle(value) - _angle;
			_rotate(_angle);
		}
		
		public function toArray():Array {
			return new Array(_point1, _point2, _point3, _point4);
		}
		
		public function toDrawArray():Array {
			var tempArray:Array = this.toArray();
			tempArray.push(_point1);
			return tempArray;
		}
		
		public function get center():Point { return _center; }
		public function set center(value:Point):void { _center = value; }
		
		public function get point1():Point { return _point1; }
		public function set point1(value:Point):void { _point1 = value; }
		
		public function get point2():Point { return _point2; }
		public function set point2(value:Point):void { _point2 = value; }
		
		public function get point3():Point { return _point3; }
		public function set point3(value:Point):void { _point3 = value; }
		
		public function get point4():Point { return _point4; }
		public function set point4(value:Point):void { _point4 = value; }	
	}
}